package com.zut.yunxi.yunxi.service.impl;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zut.yunxi.yunxi.dao.TOrderDao;
import com.zut.yunxi.yunxi.entity.TOrderEntity;
import com.zut.yunxi.yunxi.entity.TProductEntity;
import com.zut.yunxi.yunxi.service.TOrderService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("tOrderService")
public class TOrderServiceImpl extends ServiceImpl<TOrderDao, TOrderEntity> implements TOrderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        String id = (String) params.get("id");
        QueryWrapper<TOrderEntity> queryWrapper=new QueryWrapper<TOrderEntity>();
        String status = (String) params.get("status");
        int i = Integer.parseInt(status);
        if(StringUtils.isNotBlank(id))
        {
            if(i==0)
                queryWrapper.eq("business_id",id);
            else
                queryWrapper.eq("customer_id",id);
        }
        if(StringUtils.isNotBlank(key))
        {
            queryWrapper.eq("id",key).or().like("no",key);
        }
        IPage<TOrderEntity> page = this.page(
                new Query<TOrderEntity>().getPage(params),
                queryWrapper

        );

        return new PageUtils(page);
    }

}